package com.service.impl;

import com.bean.entity.*;
import com.bean.vo.StudentInfoVo;
import com.bean.vo.StudentScoreStatisticalVo;
import com.bean.vo.StudentScoreVo;
import com.dao.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TransScoreToEnrollmentRate {
    @Autowired
    private StudentScoreMapper studentScoreMapper;
    @Autowired
    private TestInfoMapper testInfoMapper;
    @Autowired
    private StudentScoreStatisticalMapper studentScoreStatisticalMapper;
    @Autowired
    private ClassesMapper classesMapper;
    @Autowired
    private SubjectInfoMapper subjectInfoMapper;
    @Autowired
    private StudentInfoMapper studentInfoMapper;

    public void transScoreToEnrollmentRate(){
        //学生信息
        List<StudentInfoVo> studentInfo = studentInfoMapper.select(new StudentInfo());
        //试卷信息
        List<TestInfo> testInfo = testInfoMapper.select(new TestInfo());
        ///各科老师输入的学生成绩信息
        List<StudentScoreVo> studentScore = studentScoreMapper.select(new StudentScore());

        for (int i = 0; i <testInfo.size() ; i++) {
            for (int j = 0; j < studentInfo.size(); j++) {
                Double languageScore=(double)0,
                mathScore=(double)0,
                englishScore=(double)0,
                physicsScore=(double)0,
                chemistryScore=(double)0,
                biologyScore=(double)0,
                geographyScore=(double)0,
                historyScore=(double)0,
                politicsScore=(double)0,
                sportsScore=(double)0,
                totalScore=(double)0;

                for (int k = 0; k <studentScore.size() ; k++) {
                    if (testInfo.get(i).getTestTime().equals(studentScore.get(k).getTestTime()) &&
                    studentInfo.get(j).getId().equals(studentScore.get(k).getStudentId())){
                        switch (studentScore.get(k).getSubjectId()){
                            case 1:
                                languageScore=studentScore.get(k).getScore();
                                break;
                            case 2:
                                mathScore=studentScore.get(k).getScore();
                                break;
                            case 3:
                                englishScore=studentScore.get(k).getScore();
                                break;
                            case 4:
                                physicsScore=studentScore.get(k).getScore();
                                break;
                            case 5:
                                chemistryScore=studentScore.get(k).getScore();
                                break;
                            case 6:
                                biologyScore=studentScore.get(k).getScore();
                                break;
                            case 7:
                                geographyScore=studentScore.get(k).getScore();
                                break;
                            case 8:
                                historyScore=studentScore.get(k).getScore();
                                break;
                            case 9:
                                politicsScore=studentScore.get(k).getScore();
                                break;
                            case 10:
                                sportsScore=studentScore.get(k).getScore();
                                break;
                        }
                    }
                }
                totalScore=languageScore+mathScore+englishScore+physicsScore+chemistryScore+biologyScore+geographyScore+
                        historyScore+politicsScore+sportsScore;

                studentScoreStatisticalMapper.insert(new StudentScoreStatistical(i*10+j+1,studentInfo.get(j).getId(),studentInfo.get(j).getStudentName()
                ,studentInfo.get(j).getClassesId(),languageScore,mathScore,englishScore,physicsScore,chemistryScore,
                        biologyScore,geographyScore,historyScore,politicsScore,sportsScore,totalScore,testInfo.get(i).getTestTime()));

            }
        }

        //学生信息统计表
        List<StudentScoreStatisticalVo> sssInfo = studentScoreStatisticalMapper.select(new StudentScoreStatistical());

        System.out.println("转换之后的学生成绩统计表是"+sssInfo);
    }

}
